package com.jiangwei.flv.controller;

import com.jiangwei.flv.service.IFLVService;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.time.LocalDateTime;
import java.util.List;

/**
 * @author jiangwei97@aliyun.com
 * @since 2023/12/11 10:42
 */
@Api(tags = "flv")
@RequiredArgsConstructor
@RestController
@RequestMapping("/flv")
public class FLVController {

    private final IFLVService service;

    @GetMapping(value = "/{channel}")
    public void open(@PathVariable(value = "channel") String channel,
                      HttpServletResponse response,
                      HttpServletRequest request) {
        String url = service.getUrl(channel);
        // String url = "rtsp://admin:hk123456@192.168.1.25:554/D3";
		if(StringUtils.isNotBlank(url)){
            service.open(url, response, request);
		}
    }

    @GetMapping(value = "/setFlag")
    public void setFlag(@RequestParam String channel) {
        String url = service.getUrl(channel);
        // String url = "rtsp://admin:hk123456@192.168.1.25:554/D3";
        if(StringUtils.isNotBlank(url)){
            service.setFlag(url);
        }
    }

    @GetMapping(value = "/getConverterUrls")
    public List<String> getConverterUrls() {
        return service.getConverterUrls();
    }

    @GetMapping(value = "/test")
    public String test() {
        return "test: " + LocalDateTime.now();
    }
}
